package com.liaozibo.demo.seckill.support.export.impl;

import com.liaozibo.demo.seckill.support.common.exception.BizException;
import com.liaozibo.demo.seckill.support.export.dto.ActivityDTO;
import com.liaozibo.demo.seckill.support.export.dto.Result;
import com.liaozibo.demo.seckill.support.export.service.ActivityExportService;
import com.liaozibo.demo.seckill.support.service.ActivityService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class ActivityExportServiceImpl implements ActivityExportService {
    @Autowired
    private ActivityService activityService;

    @Override
    public Result<ActivityDTO> getActivityByCode(String code) {
        ActivityDTO activityDTO = activityService.getActivityByCode(code);
        return Result.ok(activityDTO);
    }

    @Override
    public Result createActivity(ActivityDTO activityDTO) {
        try {
            activityService.createActivity(activityDTO);
            return Result.ok();
        } catch (BizException e) {
            return Result.fail(e.getMessage());
        }
    }

    @Override
    public Result startActivity(String code) {
        try {
            activityService.startActivity(code);
            return Result.ok();
        } catch (BizException e) {
            return Result.fail(e.getMessage());
        }
    }

    @Override
    public Result endActivity(String code) {
        try {
            activityService.endActivity(code);
            return Result.ok();
        } catch (BizException e) {
            return Result.fail(e.getMessage());
        }
    }

}
